﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BlawkayEngine.ScreenSystem
{
    public class ControllerSignInScreen : Screen
    {
        public ControllerSignInScreen(Game oGame)
            : base(oGame)
        {
            _Player1 = new PlayerInfo("Player 1", 1);
            _Player2 = new PlayerInfo("Player 2", 2);
            _Player3 = new PlayerInfo("Player 3", 3);
            _Player4 = new PlayerInfo("Player 4", 4);
        }

        public override void Update(ScreenManager oManager)
        {
        }

        public override void Draw(ScreenManager oManager, SpriteBatch oSB)
        {
        }

        public override void ActionWhenFullyAdded(ScreenManager oManager)
        {
        }

        public override void ActionWhenFullyRemoved(ScreenManager oManager)
        {
        }

        protected virtual void Select(ScreenManager oManager)
        {
            _Player1._IsReady = true;
        }

        protected virtual void Cancel(ScreenManager oManager)
        {
            _Player1._IsReady = false;
        }

        protected virtual void Finish(ScreenManager oManager)
        {
            if (PlayersAreReady)
            {
                Enabled = false;
                oManager.RemoveScreen(this);
            }
        }

        public bool PlayersAreReady
        {
            get
            {
                return (_Player1._IsReady || _Player2._IsReady || _Player3._IsReady || _Player4._IsReady);
            }
        }

        protected PlayerInfo _Player1;
        protected PlayerInfo _Player2;
        protected PlayerInfo _Player3;
        protected PlayerInfo _Player4;
    }

    public class PlayerInfo
    {
        public int _PlayerNumber;
        public float _Transition;
        public bool _IsReady;
        public string _Name;

        public PlayerInfo(string oName, int oNumber)
        {
            _Name = oName;
            _IsReady = false;
            _Transition = 0.0f;
            _PlayerNumber = oNumber;
        }

        public void ToggleReady()
        {
            _IsReady = !_IsReady;
        }

        public string DefaultName
        {
            get { return "PLAYER " + _PlayerNumber; }
        }
    }

}
